
package com.rt.schedulenew.web;
import com.rt.schedulebase.dto.*;
import com.rt.schedulenew.api.IDictDeptService;
import com.rt.schedulenew.service.impl.ConfigServiceImpl;
import com.rt.schedulebase.dto.RuleDto;
import org.apache.commons.lang3.StringUtils;
import com.rt.schedulebase.entity.DictDept;
import com.rt.schedulenew.utils.base.ConstantsUtil;
import com.rt.schedulenew.utils.base.CommonUtil;
import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.Map;
import com.rt.schedulenew.utils.global.JsonResultUtil;
import com.rt.schedulenew.utils.global.JsonResult;
import org.springframework.web.bind.annotation.RequestBody;
import com.rt.schedulenew.api.IDictExamQueueService;
import com.rt.schedulenew.api.IExamApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import com.rt.schedulenew.api.IExamScheduleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping({ "/detail" })
public class DetailController
{
    @Autowired
    private IExamScheduleService examScheduleService;
    @Autowired
    private IExamApplyService examApplyService;
    @Autowired
    private IDictDeptService dictDeptService;
    @Autowired
    private ConfigServiceImpl configServiceImpl;
    @Autowired
    private IDictExamQueueService dictExamQueueService;

    /**
     * 预约队列和时段详情
     * @param dto
     * @return
     */
    @PostMapping({ "/getScheduleDetailSum" })
    public JsonResult getScheduleDetailSum(@RequestBody ExamScheduleDto dto) {
        Map<String, Object> map = examScheduleService.getScheduleDetailSum(dto);
        return JsonResultUtil.success("成功", map);
    }

    /**
     * 获取预约的数量统计
     * @param dto
     * @return
     */
    @PostMapping({ "/getScheduleDetailList" })
    public JsonResult getScheduleDetailList(@RequestBody ExamScheduleDto dto) {
        List<ExamApplyDto> list = examScheduleService.getScheduleDetailList(dto);
        return JsonResultUtil.success("成功", list);
    }
    
    @PostMapping({ "/delScheduleApmMulti" })
    public JsonResult delScheduleApmMulti(@RequestBody ExamScheduleDto dto) {
        JsonResult jsonResult = examApplyService.delScheduleApmMulti(dto);
        if (jsonResult.getStatus().equals("0")) {
            List<ExamApplyDto> eaList = (List<ExamApplyDto>)jsonResult.getResult();
            for (ExamApplyDto ea : eaList) {
                if (!"01".equals(ea.getScheduleStatus())) {
                    ExamApplyDto examApplyDto = new ExamApplyDto();
                    List<String> applyNos = CommonUtil.mergeNo2ApplyNos(ea.getMergeNo());
                    examApplyDto.setApplyNos(applyNos);
                    examApplyDto.setActType(ea.getType());
                    examApplyDto.setExamClass(ea.getExamClass());
                    examApplyDto.setScheduledId(ea.getScheduledId());
                    examApplyDto.setMergeNo(ea.getMergeNo());
                    examApplyDto.setApplyNo(dto.getApplyNo());
                    configServiceImpl.isScheduleSync(examApplyDto, ea.getType(), ConstantsUtil.ScheduleStatus.NINE.getStatus());
                }
            }
        }
        return jsonResult;
    }
    
    @PostMapping({ "/editScheduleQueueMulti" })
    public JsonResult editScheduleQueueMulti(@RequestBody ExamScheduleDto dto) {
        JsonResult jsonResult = examScheduleService.editScheduleQueueMulti(dto);
        return jsonResult;
    }
    
    @PostMapping({ "/stopSourceForQueueName" })
    public JsonResult stopSourceForQueueName(@RequestBody ExamScheduleDto dto) {
        JsonResult jsonResult = examScheduleService.stopSourceForQueueName(dto);
        return jsonResult;
    }
    
    @PostMapping({ "/getDateSourceInfo" })
    public JsonResult getDateSourceInfo(@RequestBody ExamScheduleDto dto) {
        JsonResult jsonResult = examScheduleService.getDateSourceInfo(dto);
        return jsonResult;
    }
    
    @PostMapping({ "/editDateSourceInfo" })
    public JsonResult editDateSourceInfo(@RequestBody ExamScheduleDto dto) {
        JsonResult jsonResult = examScheduleService.editDateSourceInfo(dto);
        return jsonResult;
    }
    
    @PostMapping({ "/findPerformDept" })
    public JsonResult findPerformDept(@RequestBody DictDeptDto dto) {
        List<DictDept> list = dictDeptService.getPerformDept(dto);
        return JsonResultUtil.success(list);
    }
    
    @PostMapping({ "/queue/getScheduleQueueDetailSum" })
    public JsonResult getScheduleQueueDetailSum(@RequestBody ExamScheduleDto dto) {
        Map<String, Object> map = examScheduleService.getScheduleQueueDetailSum(dto);
        return JsonResultUtil.success("成功", map);
    }
    
    @PostMapping({ "/getLocationList" })
    public JsonResult getLocationList(@RequestBody DictExamQueueDto dto) {
        if (StringUtils.isBlank((CharSequence)dto.getQueueType())) {
            dto.setQueueType("0");
        }
        List<String> locationList = dictExamQueueService.getLocationList(dto);
        return JsonResultUtil.success("成功", locationList);
    }
    
    @PostMapping({ "/getApmRegularTypeList" })
    public JsonResult getApmRegularTypeList(@RequestBody ExamScheduleDto dto) {
        List<RuleDto.ComboBox> regularTypeList = examScheduleService.getApmRegularTypeList(dto);
        return JsonResultUtil.success("成功", regularTypeList);
    }
}
